package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_CHANGE_REGION_FROM_CROSS,desc = "跳转区域")
public class DouLuoDaLuChangeRegionCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuChangeRegionCrossRespMsg crossRespMsg = DouLuoDaLuProto.DouLuoDaLuChangeRegionCrossRespMsg.parseFrom(packet.getBytes());

        if(crossRespMsg.hasConsume() && !StringUtils.isNullOrEmpty(crossRespMsg.getConsume())){
            player.getModule(PreReduceModule.class).restorePreReduce(crossRespMsg.getConsume());
        }

        if(crossRespMsg.getRet() == 0){
            if(crossRespMsg.hasConsume() && !StringUtils.isNullOrEmpty(crossRespMsg.getConsume())){
                player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(crossRespMsg.getConsume()), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuChangeRegionConsume);
            }
        }

        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_CHANGE_REGION, crossRespMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
